﻿/*
 * This software is the confidential and proprietary
 * information of NetBay
 * Such confidential information should not be disclosed
 * NetBay copyright(c) 2010
 */

#region Using
using NetBay.Core.Extensions;
using NetBay.Core.DataAccess;
using System.ComponentModel;
using System.Data;
#endregion

namespace Rio.Doc.DataAccess
{
    public class DA_Group
    {
        #region Enum

        /// <summary>
        /// List of DB functions to access data
        /// </summary>
        public enum DbFunction
        {
            [DescriptionAttribute("")]
            None,
            [DescriptionAttribute("P_GROUP_Get_ByUserId")]
            GetGroupByUserId,
            [DescriptionAttribute("P_GROUP_List")]
            GetAllGroup,
            [DescriptionAttribute("P_GROUP_Get_ByOrgaId")]
            GetAllGroupByOrganizationId,
        }

        #endregion
        
        /// <summary>
        /// Gets the group by user.
        /// </summary>
        /// <param name="p_lUserId">The user id.</param>
        /// <returns></returns>
        public static IDataReader GetGroupByUser(long p_lUserId)
        {
            var db = DbHelper.DataBase;
            var dbCommand = db.GetNewCommand(DbFunction.GetGroupByUserId.szGetDescription());
            db.AddInParameter(dbCommand, "p_userId", DbType.Int64, p_lUserId);
            return db.ExecuteReader(dbCommand);
        }

        /// <summary>
        /// Gets all group.
        /// </summary>
        /// <returns></returns>
        public static IDataReader GetAllGroup()
        {
            var db = DbHelper.DataBase;
            var dbCommand = db.GetNewCommand(DbFunction.GetAllGroup.szGetDescription());
            return db.ExecuteReader(dbCommand);
        }

        /// <summary>
        /// Gets all RIO Organization group.
        /// </summary>
        /// <param name="p_lOrganizationId">Organization Id.</param>
        /// <returns></returns>
        public static IDataReader GetAllGroupRioByOrganization(long p_lOrganizationId)
        {
            //Log.
            NetBay.Core.Log.LogManager.Instance().LogDebug("DA_Group.GetAllGroupRioByOrganization (p_lOrganizationId <" + p_lOrganizationId.ToString() + ">)...");

            try 
	        {	
                //Variable initialization.        
		        var db = DbHelper.DataBase;
                var dbCommand = db.GetNewCommand(DbFunction.GetAllGroupByOrganizationId.szGetDescription());
                db.AddInParameter(dbCommand, "p_OrgaId", DbType.Int64, p_lOrganizationId); 

                return db.ExecuteReader(dbCommand);
            }
	        catch (System.Exception ex)
	        {
                //Error.
                NetBay.Core.Log.LogManager.Instance().LogError("DA_Group.GetAllGroupRioByOrganization Exception [" + ex.Message + "]");
                return null;
	        }        
        }
    }
}
